#------------------------------------------------------------------------------
# osxSysPrefs.pl
#   Plugin for MacRipper
#   gets some System values, like the device name
#
# Change history
#   20111227 [fpi] % created
#   20120206 [fpi] * first version
#   20120605 [fpi] * released
#
# References
#
# copyright 2011 Francesco Picasso <francesco.picasso@gmail.com>
#------------------------------------------------------------------------------

package osxSysPrefs;
use strict;

#------------------------------------------------------------------------------

my %config = (
    version         => 20120605,
    hasDescr        => 1,
    hasRefs         => 0,
	applyto			=> 'osx',
	srctype			=> "plist",
   	srcfile		    => "preferences.plist",
    srcpath		=> "/Library/Preferences/SystemConfiguration/"
);

sub getConfig       { return %config; }
sub getDescription  { return "Gets the System key values"; }
sub getReferences   { return ""; }
sub getSourcePath   { return $config{srcpath}; }
sub getSourceFile   { return $config{srcfile}; }
sub getSourceType   { return $config{srctype}; }
sub getVersion      { return $config{version}; }
sub getApplyTo      { return $config{applyto}; }

#------------------------------------------------------------------------------
# helpers

my $VERSION = getVersion();
my $tab;
my $tab0 = '';
my $tab1 = '....';
my $tab2 = $tab1.$tab1;
my $tab3 = $tab1.$tab1.$tab1;
my $noalign = "%s";
my $align10 = "%-10s";
my $align15 = "%-15s";
my $align20 = "%-20s";
my $align25 = "%-25s";

#------------------------------------------------------------------------------

sub pluginmain {
	my $class = shift;
	my $plist = shift;
	::logMsg("Launching osxSysPrefs v.".$VERSION);
    die "Invalid PLIST object" if ( not defined $plist );

	#use Data::Dumper; print Dumper($plist); return;

    my $key; my $key0; my $key1; my $key2; my $key3;
    my $val;

    $key0 = 'System';
    my $sysDct = ::getPlistKeyValue( $plist, $key0 );
    if ( not defined $sysDct ) { ::rptMsg("[$key0] not found"); return; }

    # working on System->Network
    $key1 = 'Network';
    ::rptMsg( $tab0.$key0 );
    my $netDct = ::getPlistKeyValue( $sysDct, $key1 );
    if ( defined $netDct ) {
        ::rptMsg( $tab1.$key1 );
        $key2 = 'HostNames';
        my $hostnamesDct = ::getPlistKeyValue( $netDct, $key2 );
        if ( defined $hostnamesDct ) {
            ::rptMsg( $tab2.$key2 );
            $key = 'LocalHostName';
            $val = ::getPlistKeyValue( $hostnamesDct, $key );
            $val = '<not defined>' unless (defined $val);
            ::rptMsg( $tab3.$key." = ".$val);
        }
        else { ::rptMsg("$key2 NOT FOUND in ".$key0.'\\'.$key1); }
    }
    else { ::rptMsg("$key1 NOT FOUND in ".$key0 ); }
    ::rptMsg("");

    # working on System->System
    $key1 = 'System';
    ::rptMsg( $tab0.$key0 );
    my $syssysDct = ::getPlistKeyValue( $sysDct, $key1 );
    if ( defined $syssysDct ) {
        ::rptMsg( $tab1.$key1 );
        ::rptPlistAllKeyValInDict( $syssysDct, $tab2, $align20 );
        # [fpi] following lines to get exactly the desired key-values
        #$key3 = 'ComputerName';
        #$val = ::getPlistKeyValue( $syssysDct, $key3 );
        #$val = '<not defined>' unless (defined $val);
        #::rptMsg( "$key1->$key2->$key3 = $val");
        #$key3 = 'ComputerNameEncoding';
        #$val = ::getPlistKeyValue( $syssysDct, $key3 );
        #$val = '<not defined>' unless (defined $val);
        #::rptMsg( "$key1->$key2->$key3 = $val");
        #$key3 = 'HostName';
        #$val = ::getPlistKeyValue( $syssysDct, $key3 );
        #$val = '<not defined>' unless (defined $val);
        #::rptMsg( "$key1->$key2->$key3 = $val");
    }
    else { ::rptMsg("$key1 NOT FOUND in ".$key0 ); }
    ::rptMsg("");
}

#------------------------------------------------------------------------------
1;